<template>
  <div>
    <el-container>
      <!-- 上半区域：顶栏 -->
      <el-header class="layout-header">
        <!-- 顶栏右侧的当前用户信息及下拉菜单 -->
        <div class="login-user">
          <span class="welcome">欢迎回来，<b>{{currentUserName}}</b>！</span>
          <el-dropdown @command="handleCommand">
            <el-avatar size="medium" :src="currentUserAvatar"></el-avatar>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-plus" command="openEditInfoDialog"><router-link to="/admin/sys/personal">修改资料</router-link></el-dropdown-item>
              <el-dropdown-item icon="el-icon-plus" command="openEditPasswordDialog"><router-link to="/admin/sys/updatePassword">修改密码</router-link></el-dropdown-item>
              <el-dropdown-item icon="el-icon-plus" divided command="openLogoutConfirm">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <!-- 顶栏的标题文字 -->
        <h1>仓鼠-进销存管理系统</h1>
      </el-header>
      <!-- 下半区域 -->
      <el-container class="layout-body">
        <!-- 下半区域的左侧边栏 -->
        <el-aside class="layout-aside">
          <el-menu
              router
              :default-active="$router.currentRoute.path"
              class="el-menu-vertical-demo"
              background-color="#7999bf"
              text-color="#fff"
              active-text-color="#fff">
            <!-- 主页 -->
            <el-menu-item index="/admin/index" class="houtai">
              <i class="el-icon-s-home"></i>
              <span>后台首页</span>
            </el-menu-item>
            <!-- 基础管理菜单 -->
            <el-submenu index="temp1">
              <template slot="title">
                <i class="el-icon-s-grid"></i>
                <span>基础管理</span>
              </template>
              <el-menu-item
                  index="/admin/basic/3">
                <i class="el-icon-s-custom"></i>
                <span slot="title">客户管理</span>
              </el-menu-item>
              <el-menu-item index="/admin/basic/1">
                <i class="el-icon-s-shop"></i>
                <span slot="title">供应商管理</span>
              </el-menu-item>
              <el-menu-item index="/admin/basic/2">
                <i class="el-icon-s-data"></i>
                <span slot="title">商品管理</span>
              </el-menu-item>
            </el-submenu>
            <!-- 进货管理菜单 -->
            <el-submenu index="temp2">
              <template slot="title">
                <i class="el-icon-box"></i>
                <span>进货管理</span>
              </template>
              <el-menu-item index="/admin/inport/update">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">修改进货数据</span>
              </el-menu-item>
              <el-menu-item index="/admin/inport/list">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">进货数据列表</span>
              </el-menu-item>
            </el-submenu>
            <!-- 退货管理菜单 -->
            <el-submenu index="temp2.5">
              <template slot="title">
                <i class="el-icon-box"></i>
                <span>退货管理</span>
              </template>
              <el-menu-item index="/admin/outport/insert">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">新增退货数据</span>
              </el-menu-item>
              <el-menu-item index="/admin/outport/update">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">修改退货数据</span>
              </el-menu-item>
              <el-menu-item index="/admin/outport/list">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">退货数据列表</span>
              </el-menu-item>
            </el-submenu>
            <!-- 销售管理菜单 -->
            <el-submenu index="temp3">
              <template slot="title">
                <i class="el-icon-money"></i>
                <span>销售管理</span>
              </template>
              <el-menu-item index="/admin/sale/1">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">商品销售</span>
              </el-menu-item>
              <el-menu-item index="/admin/inport/2">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">销售退货查询</span>
              </el-menu-item>
            </el-submenu>
            <!--库存管理模块-->
            <el-submenu index="/admin/repertory">
              <template slot="title">
                <i class="el-icon-s-home"></i>
                <span>库存管理</span>
              </template>
              <el-menu-item index="/admin/repertory/list">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">库存列表</span>
              </el-menu-item>
            </el-submenu>
            <!-- 系统管理菜单 -->
            <el-submenu index="temp4">
              <template slot="title">
                <i class="el-icon-setting"></i>
                <span>系统管理</span>
              </template>
              <el-menu-item index="/admin/sys/5">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">部门管理</span>
              </el-menu-item>
              <el-menu-item index="/admin/sys/4">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">角色管理</span>
              </el-menu-item>
              <el-menu-item index="/admin/sys/2">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">用户管理</span>
              </el-menu-item>
            </el-submenu>
            <!--商品报销管理模块-->
            <el-submenu index="/admin/breakage">
              <template slot="title">
                <i class="el-icon-tickets"></i>
                <span>商品报销管理</span>
              </template>
              <el-menu-item index="/admin/breakage/show">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">报损清单</span>
              </el-menu-item>
            </el-submenu>
            <!-- 其他管理菜单 -->
            <el-submenu index="temp5">
              <template slot="title">
                <i class="el-icon-more"></i>
                <span>其他管理</span>
              </template>
              <el-menu-item index="/admin/other/1">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">日志</span>
              </el-menu-item>
              <el-menu-item index="/admin/other/2">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">发布通知</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 下半区域的右侧主体 -->
        <el-main class="layout-main">
          <!-- 由其它视图组件来显示 -->
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style>
.layout-header {
  background: #193857 ;
}

.layout-header .login-user {
  float: right;
  margin-top: 12px;
  display: flex;
}

.layout-header .login-user .welcome {
  line-height: 36px;
  color: #fff;
  margin-right: 10px;
}

.layout-header h1 {
  color: #fff;
  line-height: 60px;
}

.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  left: 0;
  right: 0;
}

.layout-aside {
  background: #7999bf ;
}

.layout-aside .el-menu {
  border: 0;
}

.layout-aside i {
  color: #fff !important;
}

.layout-main {
  background: #fff;
}

.el-menu-item.is-active {
  background: #7999bf ;
}
/*后台管理的组件*/
/*.houtai{
  background: #7999bf !important; ;
}*/
</style>

<script>
export default {
  data() {
    return {
      currentUserName: '',
      currentUserAvatar: ''
    }
  },
  methods: {
    handleCommand(command) {
      if (command == 'openEditInfoDialog') {
        this.openEditInfoDialog();
      } else if (command == 'openEditAvatarDialog') {
        this.openEditAvatarDialog();
      } else if (command == 'openEditPasswordDialog') {
        this.openEditPasswordDialog();
      } else if (command == 'openLogoutConfirm') {
        this.openLogoutConfirm();
      }
    },
    openEditInfoDialog() {
      console.log('准备弹出修改当前用户资料的对话框');
    },
    openEditAvatarDialog() {
      console.log('准备弹出修改当前用户头像的对话框');
    },
    openEditPasswordDialog() {
      console.log('准备弹出修改当前用户密码的对话框');
    },
    openLogoutConfirm() {
      let message = '您确定退出登录吗？';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        localStorage.removeItem('localJwt');
        this.$router.push('/login');
      }).catch(() => {
      });
    },
    loadCurrentUserInfo() {
      this.currentUserName = localStorage.getItem('currentUserName');
      this.currentUserAvatar = localStorage.getItem('currentUserAvatar');
    }
  },
  mounted() {
    this.loadCurrentUserInfo();
  }
}
</script>